﻿@page "/search"
@inherits ListComponent<SearchPostInfo>

<PageTitle>全文搜索 - @AppConfig.AppTitle</PageTitle>

<div class="container cl-container cl-search">
	<div>
		<CmsCard Class="cl-searchs" Icon="far fa-search" Title="@($"关键词：{Key}")">
			@if (Result.TotalCount == 0)
			{
				<AntEmpty />
			}
			else
			{
				foreach (var post in Result.PageData)
				{
					var title = CmsUtils.GetSearchHtml(Key, post.Title);
					var summary = CmsUtils.GetSearchHtml(Key, post.Summary);
					var typeName = Utils.ConvertTo<ContentType>(post.Type).GetDescription();

					<div class="item">
						<div class="title">
							<a href="@Url.GetSearchUrl(post)">@((MarkupString)title)</a>
							<span><AntTag Color="blue">@typeName</AntTag> | @post.PublishTime.ToString("yyyy-MM-dd HH:mm")</span>
						</div>
						<div class="summary">@((MarkupString)summary)</div>
					</div>
				}
				<div style="padding:15px 0;text-align:center;">
					<AntPagination TotalCount="Result.TotalCount" PageSize="Criteria.PageSize" PageIndex="Criteria.PageIndex" />
				</div>
			}
		</CmsCard>
	</div>
	<div>
        <UPostRank Service="Service" />
	</div>
</div>

@code {
	private ISiteService Service;

	[SupplyParameterFromQuery] public string Key { get; set; }

	protected override async Task OnInitAsync()
	{
		await base.OnInitAsync();
		Service = await CreateServiceAsync<ISiteService>();
		Criteria.Parameters["Key"] = Key;
		Result = await Service.SearchPostsAsync(Criteria);
	}
}